package com.etc.controller;

import com.etc.pojo.CarMstPojo;
import com.etc.pojo.EmpMst;
import com.etc.pojo.Result;
import com.etc.service.CarService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/car")
public class CarController {

    @Autowired
    CarService carService;

    @PostMapping("/addCar")
    public Result add(CarMstPojo carMstPojo) {

        carService.addCar(carMstPojo);

        return Result.ok("添加成功！");
    }

    @GetMapping("search")
    public Result search(CarMstPojo pojo) {

        PageHelper.startPage(pojo.getPageNo(), pojo.getPageSize());

        List<CarMstPojo> elist = carService.findByCondition(pojo);

        PageInfo<CarMstPojo> pageInfo = new PageInfo<>(elist);
        pageInfo.setTotal(pageInfo.getTotal());
        pageInfo.setPages(pageInfo.getPages());
        pageInfo.setPageNum(pageInfo.getPageNum());

        return Result.ok(pageInfo);
    }
}
